// pages/app/schoolInfo/schoolInfo.js
const app = getApp();
var host = app.globalData.host;
var utils = app.globalData.utils;
var self = null;

Page({
  data: {
    themeColor: '',
    defaultColor: '',
    borderColor: '',
    schoolId: '',
    info: {},
    selectedTab: 0,
    imageList: []
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
    self.setData({
      schoolId: options.schoolId
    })
    self.init();
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  init() {
    var url = host + '/lx/mini/school/info';
    var params = {
      id: self.data.schoolId
    };
    var success = function (res) {
      self.setData({
        info: res.info
      })
      wx.setNavigationBarTitle({
        title: self.data.info.name
      })
      if (self.data.info.images) {
        var list = self.data.info.images.split(";");
        list.pop();
        self.setData({
          imageList: list
        })
      }
    }
    var fail = function () { };
    var complete = function () { };
    utils.request(url, params, success, fail, complete);
  },
  selectTab(event) {
    var index = Number(event.currentTarget.dataset.id)
    self.setData({
      selectedTab: index
    })
  },
  goMajors(event) {
    wx.navigateTo({
      url: '/pages/app/schools/majors/majors?schoolId=' + self.data.schoolId
    })
  }
})